<template>
  <div>
    <el-input size="mini" placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
    <el-tree
      :data="data"
      :props="defaultProps"
      node-key="catId"
      ref="menuTree"
      @node-click="nodeClick"
      :filter-node-method="filterNode"
      :highlight-current = "true"
    ></el-tree>
  </div>
</template>

<script>

import { categoryTree } from '@/api/product/category'

export default {
  components: {},
  props: {},
  data() {
    //这里存放数据
    return {
      filterText: "",
      data: [],
      expandedKey: [],
      defaultProps: {
        children: "children",
        label: "name"
      }
    };
  },
  watch: {
    filterText(val) {
      this.$refs.menuTree.filter(val);
    }
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    getCategoryTree() {
      categoryTree().then(res => {
        this.data = res.data;
      });
    },
    nodeClick(data, node, component) {
      this.$emit("tree-node-click", data, node, component);
    }
  },
  created() {
    this.getCategoryTree();
  },
};
</script>
<style scoped>

</style>
